#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
    int num=0,fh=1;
    char c=getchar();
    while(c<'0'||c>'9')
    {
        if(c=='-')fh=-fh;
        c=getchar();
    }
    while(c>='0'&&c<='9')
    {
        num=num*10+c-'0';
        c=getchar();
    }
    return num*fh;
}       
int n;
const int N=2e5+1;
int ans[2001];
int a[2001];
int maxn=-1;
void check()
{
    int sco=0;
    for(int i=1;i<=n;i++)
    {
        for(int j=i-1;j>0;j--)
        {
            if(ans[i]==ans[j])
            {
                if(a[i]==a[j])sco+=a[i];
                break;
            }
        }
    }
    maxn=max(sco,maxn);
}
void dfs(int dep,int val)
{
    if(dep==n+1)
    {
        check();
        return ;
    }
    ans[dep]=val;
    dfs(dep+1,1);
    dfs(dep+1,2);
    
}
signed main()
{   
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int T=read();
    while(T--)
    {
        n=read();
        for(int i=1;i<=n;i++)a[i]=read();
        maxn=-1;
        dfs(1,1);
        dfs(1,2);
        cout<<maxn<<endl;
    }
    return 0;
}